Skip to content

feat: Add reason, variant to flagsmith eval output - #74

Open
khvn26 wants to merge 2 commits into
mainfrom
feat/eval-reason
Open

feat: Add reason, variant to flagsmith eval output#74
khvn26 wants to merge 2 commits into
mainfrom
feat/eval-reason

Conversation

@khvn26

@khvn26 khvn26 commented Aug 7, 2026

Copy link
Copy Markdown
Member

Closes #73.

$ flagsmith eval --identity test-id
FEATURE             ENABLED   VALUE           VARIANT   REASON
beta_dashboard      on        preview                   TARGETING_MATCH; segment=identity_overrides
checkout_button     on        blue_button     blue      SPLIT; weight=50
max_items           on        25                        DEFAULT
priority_support    on        24h                       TARGETING_MATCH; segment=Power users
  • reason and variant in --json, the table and the detail view, from Flag.Reason/Flag.Variant
  • Both omitempty: an SDK API reporting neither renders exactly as it does today
  • A column appears only where something would go in it

Note the core API sends variant only, on POST /identities/reason comes from Edge.

`eval` has only ever said what an SDK resolves, never why. A flag that is on
because of a segment override, an identity override or a percentage split all
looked identical, so answering "why is this on for that user" meant leaving the
terminal for the dashboard.

flagsmith-go-client#221 puts `Reason` and `Variant` on `Flag`, populated from
the engine in local evaluation and from the `reason` and `variant` fields of
`/flags` and `/identities` remotely. This surfaces both.

Both are `omitempty` rather than always present. The EvaluationResult schema
marks them required, but an SDK API that predates them reports neither, and no
variant applies to a standard feature or to an evaluation with no identity to
bucket. An empty string would read as a reason of its own, so absence is the
honest answer — the same treatment `segments` already gets, and what keeps
`--json` a subset rather than a fiction.

The table grows a column only where there is something to put in it, so an API
reporting neither renders exactly as it does today. `--js` is deliberately
untouched: a frontend SDK hydrates from enabled and value, and anything else is
state it would carry without ever reading.

go.mod pins a pseudo-version until #221 is merged and released.

beep boop
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ef12265f-cc54-4c52-9885-125081f7e9b1

📥 Commits

Reviewing files that changed from the base of the PR and between 5bda84a and c033851.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • go.mod
  • internal/cmd/cmd_test.go
  • internal/cmd/evaluate.go

📝 Walkthrough

Walkthrough

The CLI now uses flagsmith-go-client/v5 version v5.2.0. Evaluation views and JSON output preserve SDK-provided reason and variant metadata. Single-feature output displays non-empty metadata. Multi-feature tables add REASON and VARIANT columns only when data exists. Tests cover standard, single-feature, and identity evaluations.

Estimated code review effort: 3 (Moderate) | ~20 minutes


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khvn26 khvn26 changed the title feat: Report why each flag resolved in flagsmith eval feat: Add reason, variant to flagsmith eval output Aug 7, 2026
The eval reason/variant work was developed against an unreleased commit,
so go.mod pinned a pseudo-version. v5.2.0 is out; pin the release.

beep boop
@khvn26
khvn26 marked this pull request as ready for review August 8, 2026 18:22
@khvn26
khvn26 requested a review from Zaimwa9 August 8, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add reason, variant to flagsmith eval output

2 participants